package org.boot.easyapi.core.service.api.impl;

import org.boot.easyapi.core.dao.JdbcOperaRepository;
import org.boot.easyapi.core.service.api.ApiService;
import org.boot.easyapi.pojo.web.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("easyapi-apiService")
public class ApiServiceImpl implements ApiService {

    @Resource
    private JdbcOperaRepository jdbcOperationAppRepository;

    @Override
    public Long insert(String table, Map<String, Object> param) {
        return jdbcOperationAppRepository.insert(table, param);
    }

    @Override
    public int[] insertBatch(String table, List<Map<String, Object>> params) {
        return jdbcOperationAppRepository.insertBatch(table, params);
    }

    @Override
    public Integer update(String table, Map<String, Object> param) {
        return jdbcOperationAppRepository.update(table, param);
    }

    @Override
    public List<Integer> updateBatch(String table, List<Map<String, Object>> param) {
        return jdbcOperationAppRepository.updateBatch(table, param);
    }



    @Override
    public Integer delete(String table, Long id) {
        return jdbcOperationAppRepository.delete(table, id);
    }

    @Override
    public int[] deleteBatch(String table, List<Long> ids) {
        return jdbcOperationAppRepository.deleteBatch(table, ids);
    }

    @Override
    public Map<String, Object> get(String table, Object id, String respKey) {
        return jdbcOperationAppRepository.getById(table, id, respKey);
    }

    @Override
    public List<Map<String, Object>> list(String table, Map<String, Object> param) {
        return jdbcOperationAppRepository.list(table, param);
    }

    @Override
    public PageResult<Map<String, Object>> page(String table, Map<String, Object> param) {
        return new PageResult<>(
                jdbcOperationAppRepository.page(table, param),
                jdbcOperationAppRepository.count(table, param)
        );
    }

    @Override
    public byte[] exportExcel(String table, Long configId, Map<String, Object> params) {
        return jdbcOperationAppRepository.exportExcel(table, configId, params);
    }

    @Override
    public String importExcel(String table, Long configId, MultipartFile file) {
        return jdbcOperationAppRepository.importExcel(table, configId, file);
    }
}
